package junit;

import dao.BookDao;
import dao.impl.BookDaoImpl;
import org.junit.Test;
import pojo.Book;
import pojo.Page;

import java.math.BigDecimal;
import java.util.List;

import static org.junit.Assert.*;

/**
 * @author Wxt
 * @create 2022-02-09 20:36
 */
public class BookDaoTest {
    private BookDao bookDao = new BookDaoImpl();
    @Test
    public void addBook() {
        bookDao.addBook(new Book(null, "软件工程", "徐萍", new BigDecimal(45), 51, 50,null));
        System.out.println("添加成功");
    }

    @Test
    public void deleteBookById() {
        bookDao.deleteBookById(22);
        System.out.println("删除成功");
    }

    @Test
    public void updateBook() {
        bookDao.updateBook(new Book(23, "软件工程", "徐萍", new BigDecimal(45), 100, 1, null));
        System.out.println("修改成功");
    }

    @Test
    public void queryForOneById() {
        Book book = bookDao.queryForOneById(23);
        System.out.println(book);
    }

    @Test
    public void queryAllBooks() {
        List<Book> books = bookDao.queryAllBooks();
        books.forEach(System.out :: println);
    }
    @Test
    public void queryForPageTotalCount() {
        int i = bookDao.queryForPageTotalCount();
        System.out.println(i);
    }
    @Test
    public void queryForItems() {
        List<Book> books = bookDao.queryForItems(2, Page.PAGE_SIZE);
        for (Book book : books) {
            System.out.println(book);
        }
    }
    @Test
    public void queryForPageTotalCountLimit() {
        int pageTotalCount = bookDao.queryForPageTotalCount(10, 80);
        System.out.println(pageTotalCount);
    }
    @Test
    public void queryForPageItems() {
        List<Book> books = bookDao.queryForPageItems(4, Page.PAGE_SIZE, 10, 80);
        books.forEach(System.out :: println);
    }
 }